﻿using System;
using System.Net;
using System.Windows;
using System.IO.IsolatedStorage;
using System.IO;

namespace PhotoUploader.Common
{
    public static class IsolatedStorageFileExtensions
    {
        public static void EnsureDirectory(this IsolatedStorageFile isoFile, string directoryPath)
        {
            if (!isoFile.DirectoryExists(directoryPath))
            {
                isoFile.CreateDirectory(directoryPath);
            }
        }

        public static void SavePicture(string filePath, byte[] pictureBytes)
        {
            using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                var dir = Path.GetDirectoryName(filePath);

                if (!isf.DirectoryExists(dir))
                    isf.CreateDirectory(dir);

                using (var stream = isf.CreateFile(filePath))
                {
                    stream.Write(pictureBytes, 0, pictureBytes.Length);
                }
            }
        }
    }
}
